package site.luojie.netty.rpc.consumer;

import site.luojie.netty.rpc.common.UserService;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author jie.luo
 * @since 2020-08-13
 */
public class ServerPool {

    private static Map<String, UserService> SERVER_POOL = new ConcurrentHashMap<>();

    public static void putServer(String key, UserService service) {
        SERVER_POOL.put(key, service);
    }

    public static boolean containsServer(String key) {
        return SERVER_POOL.containsKey(key);
    }

    public static void removeServer(String key) {
        SERVER_POOL.remove(key);
    }

    public static Collection<UserService> getServers() {
        return SERVER_POOL.values();
    }

    public static UserService getServer(String key) {
        return SERVER_POOL.get(key);
    }

    public static Set<String> getServersKey() {
        return SERVER_POOL.keySet();
    }

    public static int getServerNum() {
        return SERVER_POOL.size();
    }

}
